// /common/http.api.js

// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)


// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	//购物车
	let addShopCar = params => vm.$u.post("/api/carts",params)
	let getShopCarList = params => vm.$u.get("/api/carts?include=goods",params)
	let checkShopNum = (id,params)=> vm.$u.put(`/api/carts/${id}`,params) //更改购物车数量
	let delShopCar = (id) => vm.$u.delete(`/api/carts/${id}`)
	let checkedCar = params => vm.$u.patch("/api/carts/checked",params)
	//收藏
	let checkCollect = id => vm.$u.post(`/api/collects/goods/${id}`)
	//商品
	let getGoodsInfo = id => vm.$u.get(`/api/goods/${id}`)
	let getGoodsList = params => vm.$u.get("/api/goods",params)
	//个人中心
	let getUserInfo = params => vm.$u.get('/api/user',params)
	let modiUserName = params => vm.$u.put('/api/user',params)
	let updateAvatar = params => vm.$u.patch("/api/user/avatar",params)
	//认证
	let authLogin = params => vm.$u.post('/api/auth/login',params)
	let authRegister = params => vm.$u.post("/api/auth/register",params)
	let authExitLogin = params => vm.$u.post("/api/auth/logout",params)
	let authGetOssToken = params => vm.$u.get("/api/auth/oss/token",params)
	//首页
	let getIndexData = params => vm.$u.get("/api/index",params)
	//挂载
	vm.$u.api = {
		authLogin,
		getIndexData,
		getUserInfo,
		authRegister,
		modiUserName,
		authExitLogin,
		authGetOssToken,
		updateAvatar,
		getGoodsInfo,
		getGoodsList,
		checkCollect,
		addShopCar,
		getShopCarList,
		checkShopNum,
		delShopCar,
		checkedCar
	};
}

export default {
	install
}
